package com.hstcs.systmes;

import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.hstcs.components.MovementComponent;
import com.hstcs.components.TransformComponent;


public class MovementSystem extends IteratingSystem {
//	@Override
//	public void update(float deltaTime) {
//		// TODO Auto-generated method stub
//		super.update(deltaTime);
//		if( (des += deltaTime )> 0.1f)
//		{
//			
//			ImmutableArray<Entity> entities= getEntities();
//			for (int i = 0; i < entities.size(); ++i) {
//				processEntity(entities.get(i), des);
//			}
//			des = 0;
//		}
//	}

	private Vector2 tmp = new Vector2();

	private ComponentMapper<TransformComponent> tm;
	private ComponentMapper<MovementComponent> mm;
	private float des =0 ;
	
	public MovementSystem() {
		super(Family.all(TransformComponent.class, MovementComponent.class).get());
		
		tm = ComponentMapper.getFor(TransformComponent.class);
		mm = ComponentMapper.getFor(MovementComponent.class);
	}

	@Override
	public void processEntity(Entity entity, float deltaTime) {
		TransformComponent pos = tm.get(entity);
		MovementComponent mov = mm.get(entity);
		
		
		
		des = 0;
		tmp.set(mov.velocity).scl(deltaTime);
		pos.pos.add(tmp.x  , tmp.y , 0.0f);

	}
}
